<?php
/*
name:black-key_action
mail:areless@gmail.com
QQ:8228680
*/
require_once('smarty/Smarty.class.php');
require_once('mysql_lib.php');
	class Action extends db{
		public $url;
		public $path;
		public $params;
		public $views;
		/*UBB turn*/
		function ubb($str) {  
$color=Array('red','blue','green');
$str=strip_tags($str);
$str=nl2br($str);
$str=eregi_replace('\[mp3\]http://([a-zA-Z0-9@:%_.~#-\?&]+)\[\/mp3\]','<object type="application/x-shockwave-flash" data="/public/audio/player.swf" id="audioplayer" class="stop" height="24" width="290">
<param name="movie" value="/public/audio/player.swf">
<param name="FlashVars" value="soundFile=http://\\1">
<param name="quality" value="high">
<param name="menu" value="false">
<param name="wmode" value="transparent">
</object>',$str);
$str=eregi_replace('\[mp3\]([a-zA-Z0-9@:%_.~#-\?&]+)\[\/mp3\]','<object type="application/x-shockwave-flash" data="/public/audio/player.swf" id="audioplayer" height="24" width="290">
<param name="movie" value="/public/audio/player.swf">
<param name="FlashVars" value="soundFile=http://\\1">
<param name="quality" value="high">
<param name="menu" value="false">
<param name="wmode" value="transparent">
</object>',$str);
$str=eregi_replace('\[url\]http://([a-zA-Z0-9@:%_.~#-\?&]+)\[\/url\]','<a href=http://\\1  target=_blank>http://\\1</a>',$str);
$str=eregi_replace('\[url\]([a-zA-Z0-9@:%_.~#-\?&]+)\[\/url\]','<a href=http://\\1  target=_blank>\\1</a>',$str);//url
$str=eregi_replace('\[url=http://([a-zA-Z0-9@:%_.~#-\?&]+)\](.+)\[\/url\]','<a href=http://\\1 target=_blank>\\2</a>',$str); 
$str=eregi_replace('\[url=([a-zA-Z0-9@:%_.~#-\?&]+)\](.+)\[\/url\]','<a href=http://\\1 target=_blank>\\2</a>',$str); 
$str=eregi_replace('\[img\]http://([a-zA-Z0-9@:%_.~#-\?&]+)\[\/img\]','<img src=http://\\1>',$str);//img 
$str=eregi_replace('\[img\]([a-zA-Z0-9@:%_.~#-\?&]+)\[\/img\]','<img src=http://\\1>',$str);//img 
$str=eregi_replace('\[h([1-6])\](.+)\[\/h[1-6]\]','<h\\1>\\2</h\\1>',$str);//h1-6 
$str=eregi_replace('\[email\]([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})\[\/email\]','<a href=mailto:\\1>\\1</a>',$str);//email 
$str=eregi_replace('\[email=([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})\](.+)\[\/email\]','<a href=mailto:\\1>\\2</a>',$str); 
$str=eregi_replace('\[b\](.+)\[\/b\]','<b>\\1</b>',$str); 
$str=eregi_replace('\[i\](.+)\[\/i\]','<i>\\1</i>',$str); 
$str=eregi_replace('\[size=(.+)\](.+)\[\/size\]','<font size=\\1>\\2</font>',$str); 
$str=eregi_replace('\[color=(.+)\](.+)\[\/color\]','<font color=\\1>\\2</font>',$str); 
$str=eregi_replace('\[sub\](.+)\[\/sub\]','<sub>\\1</sup>',$str);//下裱 
$str=eregi_replace('\[sup\](.+)\[\/sup\]','<sup>\\1</sup>',$str);//上标 
for($i=0;$i<=count($color);$i++)$str=eregi_replace('\['.$color[$i].'\](.+)\[\/'.$color[$i].'\]','<font color='.$color[$i].'>\\1</font>',$str); 
$str=preg_replace("/\[quote\](.+?)\[\/quote\]/is","<blockquote><font size='1' face='Courier New'>quote:</font><hr>\\1<hr></blockquote>", $str); 
$str=preg_replace("/\[code\](.+?)\[\/code\]/is","<blockquote><font size='1' face='Times New Roman'>code:</font><hr color='lightblue'><i>\\1</i><hr color='lightblue'></blockquote>", $str); 
$str=preg_replace("/\[sig\](.+?)\[\/sig\]/is","<div style='text-align: left;color: darkgreen;margin-left: 5%'><br><br>--------------------------<br>\\1<br>--------------------------</div>", $str); 
return $str; 
} 
		function timecut( $loadtime )
		{
			if ((time()-$loadtime)<86400) {
			$h=date("G", time()-$loadtime);
			$i=date("i", time()-$loadtime);
			$s=date("s", time()-$loadtime);
			if ($h==0) {
				$mytime=(int)$i.'分钟前';
				if ($i==0) {
				$mytime=(int)$s.'秒前';
				}
			}else {
				if (!($mytime)) {
				$mytime=$h.'时'.(int)$i.'分钟前';
				}
			}
			}else{
			$m=date("n", time()-$loadtime);
			$j=date("j", time()-$loadtime);
			if (($m-1)==0) {
			$h=date("G", time()-$loadtime);
			$mytime=($j-1).'天'.$h.'小时前';
			}else {
			$mytime=$m.'月'.($j-1).'天前';
			}
			if ((time()-$loadtime)>31536000) {
			$y=date("Y", time()-$loadtime);
			$y=$y-1970;
			$mytime=$y.'年'.$m.'月前';
			}
			}
			return $mytime;
		}
		function viewset($var, $cacheid = NULL, $compileid = NULL)
		{
		global $view;
		$output = $view->fetch($var, $cacheid, $compileid);
		echo $output;
		}
		public function Action ()
		{
			$this->url=$_GET['url'];
			$this->path=explode('/',$this->url,2);
		}
		public function controllerPath()
		{
			return $this->path[0];
		}
		public function controllerParams()
		{
			$this->path=explode('/',$this->path[1]);
			return $this->path;
		}
	}
	$Action =& new Action();
	$Path=( $Action->controllerPath() )?( $Action->controllerPath() ):'index';
	$controllerName=$Path;
	$Path.='Controller';
	if ( is_file ( 'controllers/'.$Path.'.php' ) )
	{
		include( 'controllers/'.$Path.'.php' );
		$controller=& new $Path;
		$Path=$Action->controllerParams();
		$controller->params=$Path;
		$Path=($Path[0])?( $Path[0] ):'index';
		if ( method_exists($controllerName.'Controller', $Path) )
		{
			$controller->$Path();
			if ( $controller->views['fin'] )
			{
				$Path='fin';
				$controller->$Path();
			}
			$view = new Smarty;
			$view->debugging = FALSE;
			$view->template_dir = 'views/'.$controllerName.'/';
			$view->compile_dir = 'temp/compile/'.$controllerName;
			$view->cache_dir = 'temp/cache/'.$controllerName;
			$view->cache_lifetime = 0;
			$view->caching = FALSE;
			$view->left_delimiter = '{#';
			$view->right_delimiter = '#}';
			if ( $controller->views )
			{
			foreach( $controller->views as $key => $value )
			{
			$view->assign($key,$value);
			}
			}
			$controller->viewset($Path.'.html');
		}else{
		include( 'controllers/indexController.php' );
		if ( method_exists('indexController',$controllerName) )
		{
			$controller=& new indexController;
			$view = new Smarty;
			$view->debugging = FALSE;
			$view->template_dir = 'views/index/';
			$view->compile_dir = 'temp/compile/index';
			$view->cache_dir = 'temp/cache/index';
			$view->cache_lifetime = 0;
			$view->caching = FALSE;
			$view->left_delimiter = '{#';
			$view->right_delimiter = '#}';
			$controller->Action();
			$controller->controllerParams();
			$controller->params=$controller->path;
			$controller->$controllerName();
			if ( $controller->views['fin'] )
			{
				$controllerName='fin';
				$controller->$controllerName();
			}
			if ( $controller->views )
			{
				foreach( $controller->views as $key => $value )
				{
				$view->assign($key,$value);
				}
			}
				$controller->viewset($controllerName.'.html');
		}else
		{
			include( 'controllers/404Controller.php' );
		}
		}
	}else
	{
		include( 'controllers/indexController.php' );
		if ( method_exists('indexController', $controllerName) )
		{
			$controller=& new indexController;
			$view = new Smarty;
			$view->debugging = FALSE;
			$view->template_dir = 'views/index/';
			$view->compile_dir = 'temp/compile/index';
			$view->cache_dir = 'temp/cache/index';
			$view->cache_lifetime = 0;
			$view->caching = FALSE;
			$view->left_delimiter = '{#';
			$view->right_delimiter = '#}';
			$controller->Action();
			$controller->controllerParams();
			$controller->params=$controller->path;
			$controller->$controllerName();
			if ( $controller->views['fin'] )
			{
				$controllerName='fin';
				$controller->$controllerName();
			}
			if ( $controller->views )
			{
				foreach( $controller->views as $key => $value )
				{
				$view->assign($key,$value);
				}
			}
				$controller->viewset($controllerName.'.html');
		}else{
		include( 'controllers/404Controller.php' );
		}
	}
?>